﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SavoryDL;
using System.Data;
using System.Data.SqlClient;

namespace SavoryBL
{
    public class SavoryAdminAccount
    {
        public ResponseStatus AdminChangePassword(int adminID, string userName, string oldPwd, string newPwd)
        {

            ResponseStatus status = ResponseStatus.Failure;
            try
            {
                Savory_ParameterList par = new Savory_ParameterList();
                par.AddIntParameter("@AdminID", adminID);
                par.AddStringParameter("@Name", userName);
                par.AddStringParameter("@Password", oldPwd);
                par.AddStringParameter("@NewPassword", newPwd);
                Int32 returnStatus = Savory_DBServices.ExecuteQuery("AdminChangePassword", System.Data.CommandType.StoredProcedure, par);

                if (returnStatus == 0)
                {
                    status = ResponseStatus.InvalidOldPassword;
                }
                else if (returnStatus == 1)
                {
                    status = ResponseStatus.Success;
                }
                else if (returnStatus == -1)
                {
                    status = ResponseStatus.Failure;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }

            return status;
        }
        public DataSet GetAdminProfileDetails(int adminID, string Name)
        {

            DataSet ds = null;
            try
            {
                Savory_ParameterList par = new Savory_ParameterList();
                par.AddIntParameter("@AdminID", adminID);
                par.AddStringParameter("@Name", Name);
                ds = Savory_DBServices.GetDataSet("GetAdminProfileByName", System.Data.CommandType.StoredProcedure, par);

            }
            catch (Exception ex)
            {

            }
            finally
            {

            }
            return ds;
        }
        public ResponseStatus AdminUpdateProfile(int adminID, string emailID, string username, string password, string name)
        {

            ResponseStatus status = ResponseStatus.Failure;
            try
            {
                Savory_ParameterList par = new Savory_ParameterList();
                par.AddIntParameter("@AdminID", adminID);
                par.AddStringParameter("@EmailID", emailID);
                par.AddStringParameter("@UserName", username);
                par.AddStringParameter("@Password", password);
                par.AddStringParameter("@Name", name);
                Int32 returnStatus = Savory_DBServices.ExecuteQuery("UpdateAdminProfileByName", System.Data.CommandType.StoredProcedure, par);

                if (returnStatus == 0)
                {
                    status = ResponseStatus.InvalidOldPassword;
                }
                else if (returnStatus == 1)
                {
                    status = ResponseStatus.Success;
                }
                else if (returnStatus == -1)
                {
                    status = ResponseStatus.Failure;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }

            return status;
        }
        public string GetAdminPasswordByEmailID(string EmailID)
        {

            DataSet ds = null;
            string pwd = string.Empty;
            try
            {
                Savory_ParameterList par = new Savory_ParameterList();
                par.AddStringParameter("@EmailID", EmailID);
                ds = Savory_DBServices.GetDataSet("GetAdminPasswordByEmailID", System.Data.CommandType.StoredProcedure, par);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    pwd = ds.Tables[0].Rows[0]["Password"].ToString();
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }
            return pwd;
        }
        public List<AdminDisplayUserList> GetListOfAllUsers()
        {
            List<AdminDisplayUserList> resultList = new List<AdminDisplayUserList>();
            SqlDataReader dr = null;
            Savory_DBServices obj = new Savory_DBServices();
            try
            {

                dr = obj.GetDataReader(1, "AdminAllUserList",0);
                while (dr.Read())
                {
                    AdminDisplayUserList ObjData = new AdminDisplayUserList();
                    ObjData.AccountNo = Convert.ToInt32(dr["AcNO"].ToString());
                    ObjData.AccountType = dr["AcType"].ToString();
                    ObjData.Name = dr["Name"].ToString();
                    ObjData.Country = dr["Country"].ToString();
                    ObjData.IsMember = Convert.ToBoolean(dr["IsMember"].ToString());
                    ObjData.UserID = Convert.ToInt32(dr["UserID"].ToString());
                    resultList.Add(ObjData);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }
            return resultList;
        }
    }
    public class AdminDisplayUserList
    {
        public AdminDisplayUserList()
        {
        }
        public int AccountNo { get; set; }
        public string AccountType { get; set; }
        public string Country { get; set; }
        public string EmailID { get; set; }
        public string FirstName { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsMember { get; set; }
        public string Landline { get; set; }
        public string LastName { get; set; }
        public string Name { get; set; }
        public long UserID { get; set; }
    }
}